package com.sys.tool;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.apache.commons.mail.SimpleEmail;

import javax.mail.MessagingException;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: mabo
 * Date: 2009-11-26
 * Time: 13:57:39
 * To change this template use File | Settings | File Templates.
 */
public class MailTool {

    private String sendMail;
    private String pwd;
    private String smtp;
    public MailTool(String mail,String pwd,String smtp){
        this.sendMail = mail;
        this.pwd = pwd;
        this.smtp = smtp;
    }
    public void post(String toMail, String Subject, String body) {
        HtmlEmail email = new HtmlEmail();
        //email.setHostName("211.88.30.145");
        email.setHostName(smtp);
        email.setAuthentication(sendMail, pwd);
        //email.setSmtpPort(26);
        try {
            // 字符编码集的设置
            email.setCharset("gbk");
            email.addTo(toMail);
            email.setFrom("mabobj@163.com");
            email.setSubject(Subject);
            /*email.buildMimeMessage();
            //设置内容的字符集为UTF-8,先buildMimeMessage才能设置内容文本
            try {
                email.getMimeMessage().setText(body, "GBK");
            } catch (MessagingException e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
            email.sendMimeMessage();*/
            email.setHtmlMsg(body);
            email.send();
        } catch (EmailException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
    }

    public static void main(String[] args) {
        System.out.println(new Date());

    }
}